{% extends "templates/atnet_base.html" %}

{% block csslink %}
{{ super() }}
<script src="/media/js/jquery.js"></script>

{% include 'templates/includes_datatable.html' %}
{% include 'templates/includes_jquery_ui.html' %}
<script src="/media/js/form_popup.js"></script>

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
	
	$('#tantiemes').dataTable({
		"bPaginate": false,
		"bLengthChange": false,
		"bFilter": true,
		"bSort": true,
		"bInfo": false,
		"bAutoWidth": false,
		"oLanguage": {
			"sUrl": "/media/js/dataTables.{{ app_user.lang }}.txt"
		},
		"bProcessing": true,
		"sAjaxSource": "{{ uri_for('creation_cles_de_repartition', imm_id=immeuble.key().id(), command='list_json') }}",
		"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
			$('td:eq(4)', nRow).html('<a href="javascript:void(0);" id="' + aData[4] + '">{{ _("Edit") }}</a>');
		}
	});

	$('#summary').dataTable({
		"bPaginate": false,
		"bLengthChange": false,
		"bFilter": true,
		"bSort": false,
		"bInfo": false,
		"bAutoWidth": false,
		"oLanguage": {
			"sUrl": "/media/js/dataTables.{{ app_user.lang }}.txt"
		},
		"bProcessing": true,
		"sAjaxSource": "{{ uri_for('creation_cles_de_repartition', imm_id=immeuble.key().id(), command='sum_json') }}",
	});
	
	
	$('#add-t').live('click', function(){
		$(this).LaunchPopup(
			{
				TableId: '#tantiemes, #summary',
				DivId: '#dialog-form',
				FormId: '#generated-form',
				UrlForm: "{{ uri_for('creation_cles_de_repartition', imm_id=immeuble.key().id(), command='add') }}",
				Mode: 'add',
				Title: '{{ _("Add tantieme") }}',
				UrlReturn: "{{ uri_for('creation_cles_de_repartition', imm_id=immeuble.key().id(), command='list') }}"
			}
		)
	});
	
	$('#tantiemes tbody tr a').live('click', function(e) {
		$(this).LaunchPopup(
			{
				TableId: '#tantiemes, #summary',
				DivId: '#dialog-form',
				FormId: '#generated-form',
				UrlForm: "{{ uri_for('creation_cles_de_repartition', imm_id=immeuble.key().id(), command='edit') }}" + e.target.id + "/",
				Mode: 'edit',
				Title: '{{ _("Edit tantieme") }}',
				UrlReturn: "{{ uri_for('creation_cles_de_repartition', imm_id=immeuble.key().id(), command='list') }}"
			}
		)
	});
});
</script>
{% endblock %}

{% block title %} 
	{{ title }}
{% endblock %}

{% block header %}
{{ header }}
{% endblock %}

{% block login%}
{% if show_login %}
{{ super() }}
{% endif %}
{% endblock%}

{% block navigation %}
{% if not show_login %}
{{ super() }}
{% endif %}
{% endblock %}

{% block section_menu %}
{% include 'templates/includes_creation_menu.html' %}
{% endblock %}

{% block main_content %}
<p>
	<div id="demo">
	<fieldset>
	<legend> <b>{{ _('Tantieme distribution')}}</b> </legend>
	<p><a href="javascript:void(0);" id="add-t">{{ _('Add tantieme') }}</a></p>
	<table cellpadding="0" cellspacing="0" border="0" class="display" id="tantiemes" width="100%">
		<thead>
			<tr>
				<th>{{ _(fields.lot) }}</th>
				<th></th>
				<th>{{ _(fields.charges_key) }}</th>
				<th>{{ _(fields.tantieme) }}</th>
				<th width="20"></th>
			</tr>
		</thead>
		<tbody>
		</tbody>
		<tfoot>
			<tr>
				<th>{{ _(fields.lot) }}</th>
				<th></th> 
				<th>{{ _(fields.charges_key) }}</th>
				<th>{{ _(fields.tantieme) }}</th>
				<th></th>
			</tr>
		</tfoot>
	</table>
	</div>
	<br />
	<div>
	<fieldset>
	<legend> <b>{{ _('Summary table')}}</b> </legend>
	<table cellpadding="0" cellspacing="0" border="0" class="display" id="summary" width="70%">
		<thead>
			<tr>
				<th>{{ _(fields.charges_key) }}</th>
				<th>{{ _('Summary value') }}</th>
				<th>{{ _('Expected value') }}</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
		<tfoot>
			<tr>
				<th>{{ _(fields.charges_key) }}</th>
				<th>{{ _('Summary value') }}</th>
				<th>{{ _('Expected value') }}</th>
			</tr>
		</tfoot>
	</table>

	</fieldset>
	</div>
	{% include 'templates/includes_popup_form.html' %}
</p>			
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
	var availableTagsCK;
	availableTagsCK = getMessages("{{ uri_for('parametrage_cles', imm_id=immeuble.key().id(), command='list_names_json') }}");
	$("#charges_key").live("focus", function() {
		$(this).autocomplete({
			delay: 0,
			minLength: 0,
			source: availableTagsCK
		});
		$(this).data("autocomplete").search($(this).val());
	});
	
	var availableTagsLots;
	availableTagsLots = getMessages("{{ uri_for('creation_lots', imm_id=immeuble.key().id(), command='list_names_json') }}");
	$("#lot").live("focus", function() {
		$(this).autocomplete({
			delay: 0,
			minLength: 0,
			source: availableTagsLots
		});
		$(this).data("autocomplete").search($(this).val());
	});
});
</script>
{% endblock %}
